from moviepy.video.VideoClip import TextClip
from moviepy.video.compositing.transitions import slide_in


def slide_text_clip(txt=None, filename=None, color='black',
                    bg_color='transparent', fontsize=40, font='Courier',
                    stroke_color=None, stroke_width=1, method='label',
                    kerning=None, align='center', width=0, height=0, y=0, duration=1, start=0):
    w, h = width, height
    text_len = len(txt)
    clips = []
    for i in range(text_len):
        clip = TextClip(txt[i], filename, (fontsize, fontsize), color, bg_color, fontsize, font, stroke_color,
                        stroke_width, method,
                        kerning,
                        align).fx(slide_in, duration=5, side='top').set_position(
            ((w - text_len * fontsize * 2) / 2 + fontsize * (i + 1), y)).set_duration(
            duration).set_start(start + (i + 1))
        clips.append(clip)
    return clips
